package com.example.utgardtutorial1.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.utgardtutorial1.entity.YsbzOpc;
import com.example.utgardtutorial1.mapper.YsbzOpcMapper;
import com.example.utgardtutorial1.service.YsbzOpcService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import static unit.Tool.lineToHump;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wwc
 * @since 2024-05-27
 */
@Service
public class YsbzOpcServiceImpl extends ServiceImpl<YsbzOpcMapper, YsbzOpc> implements YsbzOpcService {
    @Override
    public void saveMap(Map<String,Object> map){
        Map<String,Object> mapToSave = new HashMap<>();
        for (String key:map.keySet()){
            //获取“.”后面的字符串
            String strBefore = key.substring(0, key.indexOf("."));
            String strAfter = key.substring(strBefore.length()+1, key.length());
            //转小写
            String strHump = lineToHump(strAfter);
            //转驼峰
            String newKey =strHump.substring(0,1)+strHump.substring(1);
            //存入新map
            mapToSave.put(newKey,map.get(key));
        }
        //map转实体
        YsbzOpc ysbzOpc = JSON.parseObject(JSON.toJSONString(mapToSave), YsbzOpc.class);
        System.out.println("ysbz");
        Date date = new Date();
        SimpleDateFormat simpleDateFormatDay = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat simpleDateFormatTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ysbzOpc.setTimeStr(simpleDateFormatTime.format(date));
        ysbzOpc.setDateStr(date);
        save(ysbzOpc);
    }
}
